﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
 

namespace BOH.ControlPanel
{
    public partial class UserList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UserListBind();
            }
        }

        public void UserListBind()
        {
            DataSet Userdst = UserClass.getUserListBySearch("", ""); ///UserClass.getListUserDataSet();
            BindUserList(Userdst);
        }

        public void UserListBind(string UserName, string UserType)
        {
            DataSet Userdst = UserClass.getUserListBySearch(UserName, UserType);
            BindUserList(Userdst);
        }

        public void BindUserList(DataSet dst)
        {
            //UserViewList.DataSource = dst;
            //UserViewList.DataBind();
            AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
            if (AspNetPager1.RecordCount != 0)
            {
                labNoRecord.Visible = false;
                AspNetPager1.Visible = true;
                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = dst.Tables[0].DefaultView;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                UserViewList.DataSource = pds;
                UserViewList.DataBind();
            }
            else
            {
                UserViewList.DataSource = null ;
                UserViewList.DataBind();
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            UserListBind(this.txtUserSearch.Text.ToString(), this.drpType.SelectedValue);
        }
        protected void butSearch_Click(object sender, EventArgs e)
        {
            UserListBind(this.txtUserSearch.Text.ToString(), this.drpType.SelectedValue);
        }

        protected void butDelet_Click(object sender, EventArgs e)
        {
            if (hiddenSelected.Value.Trim().Length > 0 && hiddenSelected.Value.Trim() != ",")
            {
                string[] arrUserID = hiddenSelected.Value.Trim().Split(new char[] {','});
                foreach (string userID in arrUserID)
                {
                    if (userID.Trim().Length > 0)
                    {
                        UserClass.DeleteUser(userID);
                    }
                }  
                UserListBind(this.txtUserSearch.Text.ToString(), this.drpType.SelectedValue);
            }
          
        }

        public string getStatus(string status)
        {
            string returnvalue = string.Empty;
            switch (status)
            { 
                case "A":
                    returnvalue = "激活";
                    break;
                case "D":
                    returnvalue = "<font color='red'>未激活</font>";
                    break;
                default:
                    break;
            }

            return returnvalue;
        }
    }
}
